<template>
  <a-modal
    :title='currentTitle'
    :width='740'
    :visible='visible'
    :confirmLoading='loading'
    @ok="() => { $emit('ok') }"
    @cancel="() => { $emit('cancel') }"
  >
    <div style='max-height: 500px;overflow: auto'>
      <a-spin :spinning='loading'>

        <a-form :form='form' v-bind='formLayout'>
          <a-form-item label='主键' v-show='false'>
            <a-input v-decorator="['id']" />
          </a-form-item>

          <a-form-item label='确认信息'>
            <a-textarea placeholder='请输入确认信息'
                        v-decorator="['confirmMessage', { rules: [{ required: true, message: '请输入确认信息!' }] }]" />
          </a-form-item>
        </a-form>
      </a-spin>
    </div>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import TagSelectOption from '@/components/TagSelect/TagSelectOption'
// 表单字段
const fields = ['confirmMessage']
export default {
  components: { TagSelectOption },
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    loading: {
      type: Boolean,
      default: () => false
    },
    model: {
      type: Object,
      default: () => null
    }
  },
  computed: {
    currentTitle () {
      return '确认告警'
    }
  },
  data () {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 19 }
      }
    }
    return {
      form: this.$form.createForm(this),
      uploadLoading: false
    }
  },
  created () {
    // 防止表单未注册
    fields.forEach(v => this.form.getFieldDecorator(v))
    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields))
    })
  },
  methods: {}
}
</script>
<style lang='less' scoped>
.ant-modal-body {
  height: 700px;
  overflow: auto;
}
</style>
